<template>
  <div class="common-layout">
    <el-container>
      <el-header>在线小说阅读后台管理系统</el-header>
      <el-container>
        <el-aside width="200px">
          <el-radio-group v-model="isCollapse" style="margin-bottom: 20px">
            <el-radio-button :value="false">展开</el-radio-button>
            <el-radio-button :value="true">收缩</el-radio-button>
          </el-radio-group>
          <el-menu
            default-active="2"
            class="el-menu-vertical-demo"
            :collapse="isCollapse"
            @open="handleOpen"
            @close="handleClose"
          >
            <el-sub-menu index="1">
              <template #title>
                <el-icon><Notebook /></el-icon>
                <span>小说管理</span>
              </template>
              <el-menu-item-group>
                <el-menu-item index="1-1" @click="toNovelList()"
                  >管理小说</el-menu-item
                >
                <el-menu-item index="1-2" @click="toNovelAdd()"
                  >添加小说</el-menu-item
                >
              </el-menu-item-group>
            </el-sub-menu>
            <el-menu-item index="2">
              <template #title>
                <el-icon><User /></el-icon>
                <span>用户管理</span>
              </template>

            </el-menu-item>
            <el-menu-item index="3">
              <el-icon><ChatSquare /></el-icon>
              <template #title>评论管理</template>
            </el-menu-item>
          </el-menu>
        </el-aside>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import { ref } from "vue";
import { useRouter } from "vue-router";
export default {
  name: "IndexView",
  setup() {
    const isCollapse = ref(false);
    const router = useRouter();
    const handleOpen = (key, keyPath) => {
      console.log(key, keyPath);
    };
    const handleClose = (key, keyPath) => {
      console.log(key, keyPath);
    };

    const toNovelList = () => {
      router.push("/index/novelList");
    };

    const toNovelAdd = () => {
      router.push("/index/novelAdd");
    };

    return {
      isCollapse,
      handleOpen,
      handleClose,
      toNovelList,
      toNovelAdd,
    };
  },
};
</script>

<style>
.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 200px;
  min-height: 400px;
}
</style>
